package dk.seqSite.utils.browser {
	import flash.external.ExternalInterface;	

	/**
	 * @author jk
	 */
	public class BrowserUtils {
		
		public static function get sBrowser() : String {
			
			if (!bIsInBrowser) {
				return EBrowsers.NO_BROWSER;
			}
			
			var sAppName : String = ExternalInterface.call("function() {return navigator.appName;}");
			var sAppVersion : String = ExternalInterface.call("function() {return navigator.appVersion;}");
			
			switch (sAppName) {
				
				// browsers based on netscape
				case "Netscape":
					
					// check for chrome
					if (sAppVersion.toLowerCase().indexOf("chrome") != -1) {
						return EBrowsers.CHROME;
					}
					
					// check safari
					if (sAppVersion.toLocaleLowerCase().indexOf("applewebkit") != -1 && sAppVersion.toLowerCase().indexOf("chrome") == -1) {
						return EBrowsers.SAFARI;
					}
					
					// firefox
					if (sAppVersion.toLocaleLowerCase().indexOf("applewebkit") == -1 && sAppVersion.toLowerCase().indexOf("chrome") == -1) {
						return EBrowsers.FIREFOX;
					}
					
					
					break;
					
				// opera
				case "Opera":
					return EBrowsers.OPERA;
					break;
				
				//internet explorer
				case "Microsoft Internet Explorer":
					return EBrowsers.MICROSOFT_INTERNET_EXPOLORER;
					break;
			}
			
			return EBrowsers.UNKNOWN_BROWSER;
		}

		public static function get bIsInBrowser() : Boolean {
			return ExternalInterface.available;
		}
	}
}
